<?php

class Zend_View_Helper_SherpaUrl extends Zend_View_Helper_Abstract
{

	/**
	 * @var array
	 */
	private $_sherpaParams = array();

	/**
	 * @return Zend_View_Helper_SherpaUrl
	 */
	public function sherpaUrl()
	{
		$this->_sherpaParams = isset($_GET['sherpa']) ? $_GET['sherpa'] : array();
		return $this;
	}

	/**
	 * @return string
	 */
	public function viewBy9()
	{
		return $this->view->urlThisPage(array('sherpa' => $this->_sherpaParams, 'mode' => '3x3'));
	}

	/**
	 * @return string
	 */
	public function viewBy36()
	{
		return $this->view->urlThisPage(array('sherpa' => $this->_sherpaParams, 'mode' => '6x6'));
	}

	/**
	 * @param integer $page
	 * @return string
	 */
	public function pagination($page)
	{
		$params = $_GET;
		$params['page'] = $page;
		return $this->view->urlThisPage($params);
	}

	/**
	 * @param integer $page
	 * @param integer $productId
	 * @return string
	 */
	public function productDetail($pageId, $productId)
	{
		$params = array();
		if(!empty($this->_sherpaParams['catId'])) {
			$params['catId'] = $this->_sherpaParams['catId'];
		}
		if(!empty($this->_sherpaParams['subcatId'])) {
			$params['subcatId'] = $this->_sherpaParams['subcatId'];
		}
		$params['id'] = $productId;
		return $this->view->urlToPage($pageId, array('sherpa' => $params));
	}

	/**
	 * @param integer $categoryId
	 * @return string
	 */
	public function category($categoryId)
	{
		$params = array();
		if(!empty($this->_sherpaParams['catId'])) {
			$params['catId'] = $this->_sherpaParams['catId'];
			$params['subcatId'] = $categoryId;
		} else {
			$params['catId'] = $categoryId;
		}
		return $this->view->urlToPage($this->view->config('pageIdCategories'), array('sherpa' => $params));
	}

}